package com.bst.web.base;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bst.common.annotation.Log;
import com.bst.common.enums.BusinessType;
import com.bst.base.domain.BaseNoteTemplate;
import com.bst.base.service.IBaseNoteTemplateService;
import com.bst.common.core.controller.BaseController;
import com.bst.common.core.domain.AjaxResult;
import com.bst.common.utils.poi.ExcelUtil;
import com.bst.common.core.page.TableDataInfo;

/**
 * 短信模板Controller
 * 
 * @author laoliu
 * @date 2024-07-01
 */
@Controller
@RequestMapping("/base/note/template")
public class BaseNoteTemplateController extends BaseController
{
    private String prefix = "base/base/template";

    @Autowired
    private IBaseNoteTemplateService baseNoteTemplateService;

    @GetMapping()
    public String template()
    {
        return prefix + "/template";
    }

    /**
     * 查询短信模板列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseNoteTemplate baseNoteTemplate)
    {
        startPage();
        List<BaseNoteTemplate> list = baseNoteTemplateService.selectBaseNoteTemplateList(baseNoteTemplate);
        return getDataTable(list);
    }

    /**
     * 导出短信模板列表
     */
    @RequiresPermissions("base:template:export")
    @Log(title = "短信模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseNoteTemplate baseNoteTemplate)
    {
        List<BaseNoteTemplate> list = baseNoteTemplateService.selectBaseNoteTemplateList(baseNoteTemplate);
        ExcelUtil<BaseNoteTemplate> util = new ExcelUtil<BaseNoteTemplate>(BaseNoteTemplate.class);
        return util.exportExcel(list, "短信模板数据");
    }

    /**
     * 新增短信模板
     */
    @RequiresPermissions("base:template:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存短信模板
     */
    @RequiresPermissions("base:template:add")
    @Log(title = "短信模板", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseNoteTemplate baseNoteTemplate)
    {
        return toAjax(baseNoteTemplateService.insertBaseNoteTemplate(baseNoteTemplate));
    }

    /**
     * 修改短信模板
     */
    @RequiresPermissions("base:template:edit")
    @GetMapping("/edit/{idNoteTemplate}")
    public String edit(@PathVariable("idNoteTemplate") Long idNoteTemplate, ModelMap mmap)
    {
        BaseNoteTemplate baseNoteTemplate = baseNoteTemplateService.selectBaseNoteTemplateByIdNoteTemplate(idNoteTemplate);
        mmap.put("baseNoteTemplate", baseNoteTemplate);
        return prefix + "/edit";
    }

    /**
     * 修改保存短信模板
     */
    @RequiresPermissions("base:template:edit")
    @Log(title = "短信模板", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseNoteTemplate baseNoteTemplate)
    {
        return toAjax(baseNoteTemplateService.updateBaseNoteTemplate(baseNoteTemplate));
    }

    /**
     * 删除短信模板
     */
    @RequiresPermissions("base:template:remove")
    @Log(title = "短信模板", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseNoteTemplateService.deleteBaseNoteTemplateByIdNoteTemplates(ids));
    }
}
